<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        padding: 0;
        margin: 0;
        list-style: none;
    }

    .p1 {
        text-align: center;
    }

    li {
        margin: 10px 0;
    }

    .box {
        display: none;
        width: 150px;
        height: 120px;
        padding: 10px 20px;
        border: 1px solid #000;
        box-shadow: 0 0 10px 10px #ccc;
        position: absolute;
        left: 0;
        bottom: 0;
        top: 0;
        right: 0;
        margin: auto;
    }
</style>

<body>
    <p class="p1">自定义右键菜单，请在页面点击右键查看效果。</p>
    <div class="box">
        <p><b>Javascript 学习</b></p>
        <li>第一课</li>
        <li>第二课</li>
        <li>第三课</li>
    </div>
</body>

</html>
<script>
    var box = document.querySelector('.box')
    window.oncontextmenu = function (e) {
        console.log(1);
        e.preventDefault();
        box.style.display = 'block'
    }
    window.onclick = function () {
        box.style.display = 'none'
    }
</script>